<template>
  <div class="menu-list-container common-card">
    <h3 v-if="!!menuTitle && menuTitle != '常用功能'" class="common-sub menu-list-title">
      {{ menuTitle }}
    </h3>
    <a-row :gutter="6" v-if="menuTitle == '常用功能'">
      <a-col v-for="(item, index) in menuList.slice(0,1)" :span="6" :key="`menu-${index}`" @click="handleClickMenu(item)">
        <div class="menu-item" style="background-color: rgba(216,241,251,0.6);border-radius: 10px;width: 100%;height: 100%;">
          <span class="title" style="font-weight: 700;font-size: 14px;position: absolute;top: 30px;">{{ item.title }}</span>
          <van-badge :content="item.badge || 0" :show-zero="false">
            <van-icon v-if="!!item.color" :size="40" class-prefix="iconfont" :name="item.icon" :class="item.color" class="icon" />
            <img v-else style="position: absolute;top: 20px;" class="icon" :src="item.icon" alt="" />
          </van-badge>          
        </div>
      </a-col>
      <a-col :span="18">
        <a-row>
          <a-col style="padding: 2px;" v-for="(item, index) in menuList.slice(1,7)" :span="8" :key="`menu-${index}`" @click="handleClickMenu(item)">
            <div style="background-color:rgba(216,241,251,0.6);border-radius: 10px;width: 100%;height: 100%;justify-content: flex-end;" class="menu-item" v-if="item.title == '我的账单' || item.title == '我的补贴'">
              <span class="title" style="font-weight: 700;font-size: 14px;">{{ item.title }}</span>  
              <van-badge class="messages" :content="item.badge || 0" :show-zero="false">
                <van-icon v-if="!!item.color" :size="40" class-prefix="iconfont" :name="item.icon" :class="item.color" class="icon" />
                <img  v-else style="width: 30px;height: 30px;" class="icon" :src="item.icon" alt="" />
              </van-badge>
            </div>
            <div style="background-color:rgba(250, 229, 224, 0.6);border-radius: 10px;width: 100%;height: 100%;justify-content: flex-end;" class="menu-item" v-else>
              <span class="title" style="font-weight: 700;font-size: 14px;">{{ item.title }}</span>  
              <van-badge class="messages" :content="item.badge || 0" :show-zero="false">
                <van-icon v-if="!!item.color" :size="40" class-prefix="iconfont" :name="item.icon" :class="item.color" class="icon" />
                <img  v-else style="width: 30px;height: 30px;" class="icon" :src="item.icon" alt="" />
              </van-badge>
            </div>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    <a-row v-else>
      <a-col class="menu-item" v-for="(item, index) in menuList" :span="6" :key="`menu-${index}`" @click="handleClickMenu(item)">
        <van-badge :content="item.badge || 0" :show-zero="false">
          <van-icon v-if="!!item.color" :size="40" class-prefix="iconfont" :name="item.icon" :class="item.color" class="icon" />
          <img v-else class="icon" :src="item.icon" alt="" />
        </van-badge>
        <span class="title">{{ item.title }}</span>
      </a-col>
    </a-row>
  </div>
</template>
<script setup>
import { Icon as VanIcon, Badge as VanBadge } from "vant";
import { inject } from "vue";
import router from "@/route/index.js";
const toast = inject("toast");
const props = defineProps({
  menuList: {
    type: Array,
    required: true,
  },
  menuTitle: {
    type: String,
  },
});
/**
 * @description: 处理菜单点击
 * @param {*} item
 */
function handleClickMenu(item) {
  if (!!item.url) {
    router.push(item.url);
  } else {
    toast.msg("敬请期待！");
  }
}
</script>
<style lang="less" scoped>
@import url("@/assets/style/params.less");
.menu-list-container {
  padding: 10px 0;
  .menu-list-title {
    padding: 10px 15px 0px 15px;
    color: @black;
  }
  .menu-item {
    padding: 8px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    .icon {
      line-height: 40px;
      width: 40px;
      height: 40px;
    }
    .title {
      font-size: 12px;
      color: @black;
    }
  }
  & + .menu-list-container {
    margin-top: 15px;
  }
}
</style>
